package com.googlecode.gwtbb.client.only.widget.form.entry;

import com.google.gwt.user.client.ui.Widget;
import com.googlecode.gwtbb.client.only.widget.basic.AsyncFileUpload;
import com.googlecode.gwtbb.client.shared.validation.FieldId;

/**
 * @author Abraham Grief
 * @version $Id$
 * @since Apr 30, 2008
 */
public class LabeledAsyncFileUploadFormEntry extends LabeledFormEntry {
	private AsyncFileUpload entryAsyncFileUpload;

	public LabeledAsyncFileUploadFormEntry(FieldId fieldId, String labelText, int row, int col, AsyncFileUpload entryAsyncFileUpload) {
		// fileUploads cannot have their value set for security reasons... so defaultValue is inapplicable
		super(fieldId, null, row, col, labelText);
		this.entryAsyncFileUpload = entryAsyncFileUpload;
	}

	public AsyncFileUpload getEntryAsyncFileUpload() {
		return entryAsyncFileUpload;
	}

	public Widget getEntryWidget() {
		return entryAsyncFileUpload;
	}

	public String getValue() {
		return entryAsyncFileUpload.getStatus() == AsyncFileUpload.STATUS_UPLOADED
			? entryAsyncFileUpload.getServerFileName()
			: null;
	}

	public void setValue(String value) {
		// fileUploads cannot have their value set for security reasons...
		// any attempt to set the value will be interpreted as resetting the form
		entryAsyncFileUpload.reset();
	}
}